﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Touch2Like.DAL;
using System.Data;
using OpenFlashChart;
using System.Collections;

namespace Touch2Like.Web.Customer.Popup
{
    public partial class Statistics : System.Web.UI.Page
    {
        OpenFlashChart.OpenFlashChart chart = new OpenFlashChart.OpenFlashChart();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (WebUtility.UserGUID == "0")
            {
                return;
            }

            if (!IsPostBack)
            {
                //Tag tag = new Tag();
                //DataTable dt = tag.GetStatisticsByTagUID(Request["TagUID"]);
                //GridView_Tag.DataSource = dt;
                //GridView_Tag.DataBind();

                //lb_Collect.Text = "Total: " + dt.Rows.Count;

                //runStatistics();
            }
        }

        void runStatistics()
        {
            //Tag tag = new Tag();
            //DataTable dt = tag.GetDayStatistics(0, Request["TagUID"], Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy") + " 00:00:00"), Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy") + " 00:00:00").AddDays(1));
            ////DataTable dt = tag.GetDayStatistics(0, Request["TagUID"], Convert.ToDateTime("12/10/2010 00:00:00"), Convert.ToDateTime("12/10/2013 00:00:00"));
            //ArrayList data1 = new ArrayList();
            //double max = 0;
            //for (double i = 0; i < 24; i++)
            //{
            //    double val = 0;
            //    if (dt.Select("TouchHour=" + i).Length > 0)
            //    {
            //        val = Convert.ToDouble(dt.Select("TouchHour=" + i)[0]["TouchCount"]);
            //        data1.Add(new LineDotValue(val));
            //        if (val > max) max = val;
            //    }
            //    else
            //    {
            //        data1.Add(0);
            //    }
            //}

            //OpenFlashChart.LineHollow line1 = new LineHollow();
            //line1.Values = data1;
            //line1.HaloSize = 0;
            //line1.Width = 2;
            //line1.DotSize = 5;

            //line1.Tooltip = "Tooltip:#val#";

            //chart.AddElement(line1);

            //chart.Title = new Title("Statistics of " + Request["TagUID"]);
            //int temp1 = Convert.ToInt32(max / 7) + 1;
            //chart.Y_Axis.SetRange(0, temp1 * 7, temp1);
            //chart.Tooltip = new ToolTip("Global tooltip:#val#");
            //chart.Tooltip.Shadow = true;
            //chart.Tooltip.Colour = "#e43456";
            //chart.Tooltip.MouseStyle = ToolTipStyle.CLOSEST;
            //OpenFlashChartControl1.EnableCache = false;
            //OpenFlashChartControl1.Chart = chart;
        }

        protected void GridView_Tag_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //GridView_Tag.PageIndex = e.NewPageIndex;
            //Tag tag = new Tag();
            //DataTable dt = tag.GetStatisticsByTagUID(Request["TagUID"]);
            //GridView_Tag.DataSource = dt;
            //GridView_Tag.DataBind();

            //lb_Collect.Text = "Total: " + dt.Rows.Count;
        }

        protected void GridView_Tag_Sorting(object sender, GridViewSortEventArgs e)
        {
            //if (Session["SortDirection"] == null) Session["SortDirection"] = "ASC";
            //if (Session["SortBy"] == null) Session["SortBy"] = "ListID";
            //if (e.SortExpression == Session["SortBy"].ToString()) Session["SortDirection"] = Session["SortDirection"] == "ASC" ? "DESC" : "ASC";
            //else Session["SortDirection"] = "ASC";

            ////UserTagDAL tag = new UserTagDAL();
            ////DataTable dt = tag.GetStatisticsByTagUID(Request["TagUID"]);
            //DataView dv = new DataView(dt);
            //Session["SortBy"] = e.SortExpression;
            //dv.Sort = GetSortBy();
            //GridView_Tag.DataSource = dv;
            //GridView_Tag.DataBind();

            //lb_Collect.Text = "Total: " + dt.Rows.Count;
        }

        string GetSortBy()
        {
            string sortby = "";

            sortby = " ListID";

            if (Session["SortBy"] != null)
            {
                if (!string.IsNullOrEmpty(Session["SortBy"].ToString()))
                {
                    sortby = " " + Session["SortBy"].ToString();
                }
            }
            else Session["SortBy"] = sortby;

            if (Session["SortDirection"] != null)
            {
                if (!string.IsNullOrEmpty(Session["SortDirection"].ToString()))
                {
                    return sortby + " " + Session["SortDirection"].ToString();
                }
            }

            return sortby + " " + "ASC";
        }
    }
}